package com.cskaoyan.market.controller.admin;

import com.cskaoyan.market.annotation.RequiresPermissionsDesc;
import com.cskaoyan.market.db.domain.MarketGoodsVo;
import com.cskaoyan.market.db.domain.MarketOrderVo;
import com.cskaoyan.market.service.AdminStatService;
import com.cskaoyan.market.util.ResponseUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServlet;
import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/admin/stat/")
public class AdminStatController extends HttpServlet {

    @Autowired
    AdminStatService adminStatService;


    @RequiresPermissions("admin:stat:user")
    @RequiresPermissionsDesc(menu = {"统计报表", "用户统计"},button = "用户")
    @GetMapping("user")
    public Object user() {
        Map<String, List<Object>> mallMap = adminStatService.user();
        return ResponseUtil.ok(mallMap);
    }

    @RequiresPermissions("admin:stat:order")
    @RequiresPermissionsDesc(menu = {"统计报表", "订单统计"},button = "订单")
    @GetMapping("order")
    public Object order() {
        List<MarketOrderVo> marketOrderList = adminStatService.order();
        return ResponseUtil.okColumn(marketOrderList);
    }

    @RequiresPermissions("admin:stat:goods")
    @RequiresPermissionsDesc(menu = {"统计报表", "商品统计"},button = "商品")
    @GetMapping("goods")
    public Object goods() {
        List<MarketGoodsVo> marketGoodsList = adminStatService.goods();
        return ResponseUtil.okGoods(marketGoodsList);
    }
}
